package com.ruoyi.web.controller.wms;

import java.util.List;
import javax.servlet.http.HttpServletResponse;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.wms.domain.WmsAreaManager;
import com.ruoyi.wms.service.IWmsAreaManagerService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 区域负责人Controller
 * 
 * @author ruoyi
 * @date 2024-12-19
 */
@RestController
@RequestMapping("/wms/areaManager")
public class WmsAreaManagerController extends BaseController
{
    @Autowired
    private IWmsAreaManagerService wmsAreaManagerService;

    /**
     * 查询区域负责人列表
     */
    @PreAuthorize("@ss.hasPermi('wms:areaManager:list')")
    @GetMapping("/list")
    public TableDataInfo list(WmsAreaManager wmsAreaManager)
    {
        startPage();
        List<WmsAreaManager> list = wmsAreaManagerService.selectWmsAreaManagerList(wmsAreaManager);
        return getDataTable(list);
    }

    /**
     * 导出区域负责人列表
     */
    @PreAuthorize("@ss.hasPermi('wms:areaManager:export')")
    @Log(title = "区域负责人", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, WmsAreaManager wmsAreaManager)
    {
        List<WmsAreaManager> list = wmsAreaManagerService.selectWmsAreaManagerList(wmsAreaManager);
        ExcelUtil<WmsAreaManager> util = new ExcelUtil<WmsAreaManager>(WmsAreaManager.class);
        util.exportExcel(response, list, "区域负责人数据");
    }

    /**
     * 获取区域负责人详细信息
     */
    @PreAuthorize("@ss.hasPermi('wms:areaManager:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return success(wmsAreaManagerService.selectWmsAreaManagerById(id));
    }

    /**
     * 新增区域负责人
     */
    @PreAuthorize("@ss.hasPermi('wms:areaManager:add')")
    @Log(title = "区域负责人", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody WmsAreaManager wmsAreaManager)
    {
        try {
            wmsAreaManager.setCreateBy(getUsername());
            return toAjax(wmsAreaManagerService.insertWmsAreaManager(wmsAreaManager));
        } catch (RuntimeException e) {
            return AjaxResult.error(e.getMessage());
        }
    }

    /**
     * 修改区域负责人
     */
    @PreAuthorize("@ss.hasPermi('wms:areaManager:edit')")
    @Log(title = "区域负责人", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody WmsAreaManager wmsAreaManager)
    {
        try {
            wmsAreaManager.setUpdateBy(getUsername());
            return toAjax(wmsAreaManagerService.updateWmsAreaManager(wmsAreaManager));
        } catch (RuntimeException e) {
            return AjaxResult.error(e.getMessage());
        }
    }

    /**
     * 删除区域负责人
     */
    @PreAuthorize("@ss.hasPermi('wms:areaManager:remove')")
    @Log(title = "区域负责人", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(wmsAreaManagerService.deleteWmsAreaManagerByIds(ids));
    }
}